package com.cts.util;

import com.cts.entity.Category;
import com.cts.entity.Tag;
import com.cts.mapper.CategoryMapper;
import com.cts.service.CategoryService;
import com.cts.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @projectName: CBlog
 * @package: com.cts.util
 * @className: DictUtils
 * @author: chentongsheng
 * @description: TODO
 * @date: 2023/4/4 10:39
 * @version: 1.0
 */
@Component
public class DictUtils {

    @Autowired
    CategoryService categoryService;

    @Autowired
    TagService tagService;

    public Map<Long, String> getCateGoryDict(){
        List<Category> list = categoryService.list();
        Map<Long, String> cateGoryDict = list.stream().collect(Collectors.toMap(Category::getId, Category::getCategoryName, (k1, k2) -> k1));
        return cateGoryDict;
    }

    public Map<Long, String> getTagDict(){
        List<Tag> list = tagService.list();
        Map<Long, String> tagDict = list.stream().collect(Collectors.toMap(Tag::getId, Tag::getTagName, (k1, k2) -> k1));
        return tagDict;
    }
}
